<?php
 /***************************************************************
 * Mor-MVC Framework, A framework that can easily let you build a powerful
 * and scalable web application based on PHP language,
 * this framewrok is a copy of the Zend Behavior Framework
 *  Copyright (C) 2010  Nabil Droussi <nabildroussi@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************/
class Registry
{
	private static $_instance = null;
        public function  __construct() {
            
        }
	private static function getInstance()
	{
		if(self::$_instance == null)
		{
			self::$_instance = new Registry();
		}
		return self::$_instance;
	}
	public static function addItem($key, &$value)
	{
            $_SESSION[$key] = $value;
	}
	public static function removeItem($key)
	{
            $reg = self::getInstance();
            if(self::isItemExists($key))
            {
                unset($_SESSION[$key]);
                return true;
            }
            return false;
	}
	public static function isItemExists($key)
	{
            $reg = self::getInstance();
            if(array_key_exists($key,$_SESSION))
                    return true;
            return false;
	}
	public static function getItem($key)
	{
		$reg = self::getInstance();
		if(self::isItemExists($key) === true)
			return $_SESSION[$key];
		return null;
	}
        public static function getAndClearItem($key)
        {
            $item = self::getItem($key);
            self::removeItem($key);
            return $item;
        }
}
?>